Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / feature / node / src / jvmTest / kotlin / org / meshtastic / feature / node / metrics / DetailDialogScrollTest.kt

Displaying Raw • Download

feature/node/src/jvmTest/kotlin/org/meshtastic/feature/node/metrics/DetailDialogScrollTest.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 7.05 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.node.metrics

Tff7b72import T7ee787androidx.compose.ui.test.ExperimentalTestApi
Tff7b72import T7ee787androidx.compose.ui.test.assertIsDisplayed
Tff7b72import T7ee787androidx.compose.ui.test.onNodeWithText
Tff7b72import T7ee787androidx.compose.ui.test.performScrollTo
Tff7b72import T7ee787androidx.compose.ui.test.v2.runComposeUiTest
Tff7b72import T7ee787androidx.compose.ui.text.AnnotatedString
Tff7b72import T7ee787androidx.compose.ui.text.buildAnnotatedString
Tff7b72import T7ee787dev.mokkery.answering.returns
Tff7b72import T7ee787dev.mokkery.every
Tff7b72import T7ee787dev.mokkery.matcher.any
Tff7b72import T7ee787dev.mokkery.mock
Tff7b72import T7ee787kotlinx.coroutines.Dispatchers
Tff7b72import T7ee787kotlinx.coroutines.ExperimentalCoroutinesApi
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.flowOf
Tff7b72import T7ee787kotlinx.coroutines.test.UnconfinedTestDispatcher
Tff7b72import T7ee787kotlinx.coroutines.test.resetMain
Tff7b72import T7ee787kotlinx.coroutines.test.setMain
Tff7b72import T7ee787org.meshtastic.core.di.CoroutineDispatchers
Tff7b72import T7ee787org.meshtastic.core.repository.FileService
Tff7b72import T7ee787org.meshtastic.core.repository.MeshLogRepository
Tff7b72import T7ee787org.meshtastic.core.repository.NodeRepository
Tff7b72import T7ee787org.meshtastic.core.repository.TracerouteResponseProvider
Tff7b72import T7ee787org.meshtastic.core.repository.TracerouteSnapshotRepository
Tff7b72import T7ee787org.meshtastic.core.resources.Res
Tff7b72import T7ee787org.meshtastic.core.resources.traceroute
Tff7b72import T7ee787org.meshtastic.core.ui.component.MeshtasticDialog
Tff7b72import T7ee787org.meshtastic.core.ui.theme.AppTheme
Tff7b72import T7ee787org.meshtastic.core.ui.util.AlertManager
Tff7b72import T7ee787org.meshtastic.feature.node.detail.NodeDetailUiState
Tff7b72import T7ee787org.meshtastic.feature.node.detail.NodeRequestActions
Tff7b72import T7ee787org.meshtastic.feature.node.domain.usecase.GetNodeDetailsUseCase
Tff7b72import T7ee787kotlin.test.AfterTest
Tff7b72import T7ee787kotlin.test.BeforeTest
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertNotNull

Tff7b72private Tff7b72const Tff7b72val Te6edf3HOP_COUNT Tff7b72= T79c0ff8T79c0ff0
Tff7b72private Tff7b72const Tff7b72val Te6edf3LAST_HOP_MARKER Tff7b72= Ta5d6ff"Ta5d6ffLAST_HOP_MARKERTa5d6ff"

T8b949e/**
* #6701: a traceroute with many hops scrolled fine live, but was cut off with no way to scroll when reopened from
* history. Root cause: [MetricsViewModel.showTracerouteDetail] and [MetricsViewModel.showLogDetail] passed
* [MeshtasticDialog] a bare `SelectionContainer { Text(...) }` as `composableMessage` - [MeshtasticDialog] only adds
* `verticalScroll` to its own wrapping column when the dialog has `choices` (a button list), so a plain text dialog's
* scrolling is entirely the caller's responsibility.
*
* A screenshot can't catch this regression: a single frame of "scrolled to top, more content below" looks identical
* whether or not scrolling actually works. [performScrollTo] is the right tool instead - it throws when the target node
* has no scrollable ancestor, so it fails exactly when the `verticalScroll` wrapper is missing.
*
* The dialog content under test is the real one: the ViewModel is driven through the production path and the
* `composableMessage` it hands [AlertManager] is what gets rendered, so reverting the fix in [MetricsViewModel] fails
* these tests.
*/
Tf0883e@OptInTb4b4b4(Te6edf3ExperimentalTestApiTff7b72::Te6edf3classTb4b4b4, Te6edf3ExperimentalCoroutinesApiTff7b72::Te6edf3classTb4b4b4)
Tff7b72class T56d364DetailDialogScrollTest Tb4b4b4{

Tff7b72private Tff7b72val Te6edf3testDispatcher Tff7b72= Te6edf3UnconfinedTestDispatcherTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3dispatchers Tff7b72= Te6edf3CoroutineDispatchersTb4b4b4(Te6edf3main Tff7b72= Te6edf3testDispatcherTb4b4b4, Te6edf3io Tff7b72= Te6edf3testDispatcherTb4b4b4, Te6edf3default Tff7b72= Te6edf3testDispatcherTb4b4b4)

Tff7b72private Tff7b72val Te6edf3meshLogRepositoryTb4b4b4: Te6edf3MeshLogRepository Tff7b72= Te6edf3mockTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3tracerouteResponseProviderTb4b4b4: Te6edf3TracerouteResponseProvider Tff7b72= Te6edf3mockTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3nodeRepositoryTb4b4b4: Te6edf3NodeRepository Tff7b72= Te6edf3mockTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3tracerouteSnapshotRepositoryTb4b4b4: Te6edf3TracerouteSnapshotRepository Tff7b72= Te6edf3mockTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3nodeRequestActionsTb4b4b4: Te6edf3NodeRequestActions Tff7b72= Te6edf3mockTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3getNodeDetailsUseCaseTb4b4b4: Te6edf3GetNodeDetailsUseCase Tff7b72= Te6edf3mockTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3fileServiceTb4b4b4: Te6edf3FileService Tff7b72= Te6edf3mockTb4b4b4(Tb4b4b4)

Tff7b72private Tff7b72val Te6edf3alertManager Tff7b72= Te6edf3AlertManagerTb4b4b4(Tb4b4b4)

Tff7b72private Tff7b72lateinit Tff7b72var Te6edf3viewModelTb4b4b4: Te6edf3MetricsViewModel

Tf0883e@BeforeTest
Tff7b72fun Td2a8ffsetUpTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3DispatchersTb4b4b4.Te6edf3setMainTb4b4b4(Te6edf3testDispatcherTb4b4b4)

Te6edf3every Tb4b4b4{ Te6edf3tracerouteResponseProviderTb4b4b4.Te6edf3tracerouteResponse Tb4b4b4} Te6edf3returns Te6edf3MutableStateFlowTb4b4b4(Tff7b72nullTb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3nodeRequestActionsTb4b4b4.Te6edf3lastTracerouteTime Tb4b4b4} Te6edf3returns Te6edf3MutableStateFlowTb4b4b4(Tff7b72nullTb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3nodeRequestActionsTb4b4b4.Te6edf3lastRequestNeighborTimes Tb4b4b4} Te6edf3returns Te6edf3MutableStateFlowTb4b4b4(Te6edf3emptyMapTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3nodeRepositoryTb4b4b4.Te6edf3nodeDBbyNum Tb4b4b4} Te6edf3returns Te6edf3MutableStateFlowTb4b4b4(Te6edf3emptyMapTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3getNodeDetailsUseCaseTb4b4b4(Te6edf3anyTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4} Te6edf3returns Te6edf3flowOfTb4b4b4(Te6edf3NodeDetailUiStateTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3tracerouteSnapshotRepositoryTb4b4b4.Te6edf3getSnapshotPositionsTb4b4b4(Te6edf3anyTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4} Te6edf3returns Te6edf3flowOfTb4b4b4(Te6edf3emptyMapTb4b4b4(Tb4b4b4)Tb4b4b4)

Te6edf3viewModel Tff7b72=
Te6edf3MetricsViewModelTb4b4b4(
Te6edf3destNum Tff7b72= T79c0ff1T79c0ff2T79c0ff3T79c0ff4Tb4b4b4,
Te6edf3dispatchers Tff7b72= Te6edf3dispatchersTb4b4b4,
Te6edf3meshLogRepository Tff7b72= Te6edf3meshLogRepositoryTb4b4b4,
Te6edf3tracerouteResponseProvider Tff7b72= Te6edf3tracerouteResponseProviderTb4b4b4,
Te6edf3nodeRepository Tff7b72= Te6edf3nodeRepositoryTb4b4b4,
Te6edf3tracerouteSnapshotRepository Tff7b72= Te6edf3tracerouteSnapshotRepositoryTb4b4b4,
Te6edf3nodeRequestActions Tff7b72= Te6edf3nodeRequestActionsTb4b4b4,
Te6edf3alertManager Tff7b72= Te6edf3alertManagerTb4b4b4,
Te6edf3getNodeDetailsUseCase Tff7b72= Te6edf3getNodeDetailsUseCaseTb4b4b4,
Te6edf3fileService Tff7b72= Te6edf3fileServiceTb4b4b4,
Tb4b4b4)
Tb4b4b4}

Tf0883e@AfterTest
Tff7b72fun Td2a8fftearDownTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3DispatchersTb4b4b4.Te6edf3resetMainTb4b4b4(Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ffshowLogDetailContentScrollsToRevealTrailingTextTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3viewModelTb4b4b4.Te6edf3showLogDetailTb4b4b4(Te6edf3titleRes Tff7b72= Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3tracerouteTb4b4b4, Te6edf3annotatedMessage Tff7b72= Te6edf3longRouteTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertShownAlertScrollsTb4b4b4(Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ffshowTracerouteDetailContentScrollsToRevealTrailingTextTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3viewModelTb4b4b4.Te6edf3showTracerouteDetailTb4b4b4(
Te6edf3annotatedMessage Tff7b72= Te6edf3longRouteTb4b4b4(Tb4b4b4)Tb4b4b4,
Te6edf3requestId Tff7b72= T79c0ff1Tb4b4b4,
Te6edf3responseLogUuid Tff7b72= Ta5d6ff"Ta5d6ffuuidTa5d6ff"Tb4b4b4,
Te6edf3overlay Tff7b72= Tff7b72nullTb4b4b4,
Te6edf3onViewOnMap Tff7b72= Tb4b4b4{ Te6edf3_Tb4b4b4, Te6edf3_ Tff7b72-Tff7b72> Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Te6edf3assertShownAlertScrollsTb4b4b4(Tb4b4b4)
Tb4b4b4}

Tff7b72private Tff7b72fun Td2a8fflongRouteTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3AnnotatedString Tff7b72= Te6edf3buildAnnotatedString Tb4b4b4{
Te6edf3repeatTb4b4b4(Te6edf3HOP_COUNTTb4b4b4) Tb4b4b4{ Te6edf3appendTb4b4b4(Ta5d6ff"Ta5d6ffHop Tffd700$Te6edf3itTa5d6ff -> Ta5d6ff"Tb4b4b4) Tb4b4b4}
Te6edf3appendTb4b4b4(Te6edf3LAST_HOP_MARKERTb4b4b4)
Tb4b4b4}

T8b949e/** Renders whatever `composableMessage` the ViewModel just handed [AlertManager], then scrolls to the last hop. */
Tff7b72private Tff7b72fun Td2a8ffassertShownAlertScrollsTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runComposeUiTest Tb4b4b4{
Tff7b72val Te6edf3message Tff7b72= Te6edf3alertManagerTb4b4b4.Te6edf3currentAlertTb4b4b4.Te6edf3valueTff7b72?.Te6edf3composableMessage
Te6edf3assertNotNullTb4b4b4(Te6edf3messageTb4b4b4, Ta5d6ff"Ta5d6ffViewModel did not raise an alert with composable contentTa5d6ff"Tb4b4b4)

Te6edf3setContent Tb4b4b4{ Te6edf3AppTheme Tb4b4b4{ Te6edf3MeshtasticDialogTb4b4b4(Te6edf3title Tff7b72= Ta5d6ff"Ta5d6ffTracerouteTa5d6ff"Tb4b4b4, Te6edf3text Tff7b72= Tb4b4b4{ Te6edf3messageTb4b4b4.Te6edf3ContentTb4b4b4(Tb4b4b4) Tb4b4b4}Tb4b4b4, Te6edf3onDismiss Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4) Tb4b4b4} Tb4b4b4}

Te6edf3onNodeWithTextTb4b4b4(Te6edf3LAST_HOP_MARKERTb4b4b4, Te6edf3substring Tff7b72= Tff7b72trueTb4b4b4)Tb4b4b4.Te6edf3performScrollToTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3assertIsDisplayedTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.17s